package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;

public class AreaConfigDaoImpl extends TempDao {
    public HashMap<String, String> getChannelConfig(long areaServerId) {
        ResultSet rs = null;
        CallableStatement call = null;
        HashMap<String, String> dataMap = new HashMap<>();
        String sql = "select * from t_n_param where channelServerId = ?";
        try {
            getDb().setConnName(DbNameStrategy.getChannelCenterDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setLong(1, areaServerId);
            rs = call.executeQuery();
            while (rs.next()) {
                String name = rs.getString("param");
                if (!dataMap.containsKey(name)) {
                    dataMap.put(name, rs.getString("value"));
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
